<template>
  <div class="calendar-bottom">
    <div class="left">
      <h2>{{ result.lunar }}</h2>
      <h3>{{ result.lunarYear }} {{ result.animalsYear }}</h3>
    </div>
    <div class="right">
      <div>
        宜: <span>{{ result.suit }}</span>
      </div>
      
      <div>
        忌: <span>{{ result.avoid }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { storeToRefs } from 'pinia'
import { useCalendarStore } from '@/stores/calendar.js'

const { formatDate } = storeToRefs(useCalendarStore())

import axios from 'axios'

const result = ref({
  lunar: '',
  lunarYear: '',
  animalsYear: '',
  suit: '',
  avoid: '',
})
const key = '2f0af268c68ebb7ce8b87a73c8224d83'
onMounted(async () => {
  try {
    const res = await axios.get(
      `/calendar/day?date=${formatDate.value}&key=${key}`
    )
    // console.log(res.data)
    result.value = res.data.result.data
  } catch (error) {
    console.error('获取农历信息失败:', error)
    // 即使API调用失败，也要确保组件能正常渲染
    result.value = {
      lunar: '未知',
      lunarYear: '未知',
      animalsYear: '未知',
      suit: '未知',
      avoid: '未知',
    }
  }
})
</script>

<style scoped>
.calendar-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 20px;
  padding: 20px;
  background-color: #f5f5f5;
  border-radius: 16px;
}
.left {
  flex: 1;
}
.right {
  flex: 3;
  span {
    font-size: 12px;
  }
}
</style>
